<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        ol {
            list-style: none;
        }

        #ipt {
            color: gray;
        }
    </style>
</head>

<body>
    <form action="">
        <input type="text" value="请输入搜索关键字" name="" id="ipt">
    </form>
    <script>
        var ipt = document.getElementById("ipt")

        ipt.onfocus = function () {
            if (ipt.value == "请输入搜索关键字") {
                this.value = ""
                this.style.color = "black"
            }
        }
        ipt.onblur = function () {
            if (this.value == "" || ipt.value == "请输入搜索关键字") {
                this.value = "请输入搜索关键字"
                this.style.color = "gray"
            }
        }
    </script>

</body>

</html>